package br.com.ebc.icontatos.utils;

import java.util.Enumeration;
import java.util.Map;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

public class LoginHelper {

	public static ExternalContext getExternalContext() {
		FacesContext facesContext = FacesContext.getCurrentInstance();
		return facesContext.getExternalContext();
	}
	
	@SuppressWarnings("unchecked")
	public static void putSessionAttribute(Object nomeAtributo, Object valor) {
		Map sessionMap = getExternalContext().getSessionMap();
		sessionMap.put(nomeAtributo, valor);
	}
	
	@SuppressWarnings("unchecked")
	public static void closeSession() {
		HttpSession session = (HttpSession) getExternalContext().getSession(false);
		Enumeration<String> en = session.getAttributeNames();
		while (en.hasMoreElements()) {
			String name = en.nextElement();
			session.removeAttribute(name);
		}
	}
	
}
